import { useTreeStore, timeNumberToStr } from '@/store/tree';
import { formateSecondTime } from '@/utils';

export default function useCurrent() {
  const treeStore = useTreeStore()

  const currentName = computed(() => treeStore.current?.name || treeStore.current?.bar_name)

  const totalTime = computed(() => {
    const { node_tree } = treeStore.menuData.find(x => x.content_id === treeStore.content_id) || {}
    if (!node_tree) return formateSecondTime(treeStore.current.duration)

    const [, totalTimeStr] = node_tree[node_tree.length - 1]?.time_duration.split('-')
    return totalTimeStr
  })

  const currentTime = computed(() => timeNumberToStr(treeStore.progressValue))

  return {
    treeStore,
    currentName,
    totalTime,
    currentTime
  }
}